﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using GanagroLiteBO;
using GLiteInterfaces;
using GeneralUtilities;

namespace GanagroLite
{
    public partial class FormBackups : WinPart, IOperacionView
    {

        public FormBackups()
        {
            InitializeComponent();
        }

        #region Internal methods

        protected internal override object GetIdValue()
        {
            return "BackupForm";
        }

        public override string ToString()
        {
            return "Copias de seguridad";
        }

        #endregion


        private void buttonBackup_Click(object sender, EventArgs e)
        {
            try
            {
                string carpetCopiaNube = BackupUtilities.GetDBBackupFileName(this.textBoxCopiaNube.Text, "GanagroDatosLite");
                string copiaDBLocal = BackupUtilities.BackupDB("GanagroDatosLite", this, this.textBoxCopiaLocal.Text);
                System.IO.File.Copy(copiaDBLocal, carpetCopiaNube,true);
                this.status2 = string.Format("{0} copiado a directorio Nube", copiaDBLocal);
                // BackupUtilities.CompressAndUploadFile(this.textBoxArchivoFtp.Text, "GanagroDatosLite", this, true, copiaDBLocal);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        public void DisplayMessage(string message)
        {
            MessageBox.Show(message);
        }


        private void FormBackups_Load(object sender, EventArgs e)
        {
            string remoteFilename = @"GDLite_" + DateTime.Now.Date.ToShortDateString() + ".gz";
            this.textBoxArchivoFtp.Text = remoteFilename.Replace(@"/", string.Empty).Replace(@"\", string.Empty);
            this.textBoxCopiaLocal.Text = BackupUtilities.GetDirectorioCopias();
            this.labelArchivoCopia.Text = string.Format("Archivo backup: {0}.bak", ConfigUtilities.GetDbConnElement("GanagroDatosLite", "DATABASE"));
        }

        private void btnSalir_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            BackupUtilities.RestaurarBD("GanagroDatosLite", this);
        }

        #region IOperacionView Members

        public string status
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                MainForm.Instance.StatusLabel1.Text = value;
                this.Update();
            }
        }

        public string status2
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                MainForm.Instance.StatusLabel2.Text = value;
                this.Update();
            }
        }

        public void SetUIBusyStatus()
        {
            // MainForm.Instance.Cursor = Cursors.WaitCursor;
            this.Update();
        }

        public void SetUIDefaultStatus()
        {
            MainForm.Instance.Cursor = Cursors.Default;
            this.Update();
        }

        #endregion
    }
}
